<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/1
  Time: 11:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

<div class="panel">
  <div class="panel-heading header">
    <h3 class="panel-title" id="title">业务洽谈登记</h3>
  </div>

  <!-- BASIC FORM ELEMENTS -->
  <!--===================================================-->
  <form id="form_businessTalk_input" class="form-horizontal">

    <input type="hidden" name="keyId" id="keyId" value="${businessTalk.id}"/>
    <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

    <div class="form-group">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_customerInfo_dialog_select()" style="color: #4FA5D0">客户名称</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input disabled type="text" id="customerInfo" class="form-control" placeholder="请输入客户名称" value="${businessTalk.customerInfo.name}">
        <input type="hidden" id="customerInfoId" name="customerInfoId" class="form-control" value="${businessTalk.customerInfo.id}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">开始时间<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择开始时间" id="startDate" name="startDate" class="form-control" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${businessTalk.startDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">结束时间<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择结束时间" id="endDate" name="endDate" class="form-control" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${businessTalk.endDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈主题<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="talkTopic" id="talkTopic" class="form-control" placeholder="请输入洽谈主题" value="${businessTalk.talkTopic}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈方式<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <div class="radio">
          <input type="radio" name="talkType" id="talkType1" value="上门拜访" class="magic-radio" <c:if test="${businessTalk.talkType=='上门拜访'}"> checked</c:if> >
          <label for="talkType1">上门拜访</label>
          <input type="radio" name="talkType" id="talkType2" value="邮件沟通" class="magic-radio" <c:if test="${businessTalk.talkType=='邮件沟通'}"> checked</c:if> >
          <label for="talkType2">邮件沟通</label>
          <input type="radio" name="talkType" id="talkType3" value="电话沟通" class="magic-radio" <c:if test="${businessTalk.talkType=='电话沟通'}"> checked</c:if> >
          <label for="talkType3">电话沟通</label>
        </div>
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈地址<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="talkAddress" id="talkAddress" class="form-control" placeholder="请输入洽谈地址" value="${businessTalk.talkAddress}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈对象<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="talkObject" id="talkObject" class="form-control" placeholder="请输入洽谈对象" value="${businessTalk.talkObject}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈内容<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="talkContent" id="talkContent" class="form-control" placeholder="请输入洽谈内容" value="${businessTalk.talkContent}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">洽谈内容附件<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input name="uploadify" id="talkFileName" placeholder="" type="file" >
        <input name="talkFileId" id="talkFileId" style="display: none" value="${talkFileId}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">参与人员<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="joinMember" id="joinMember" class="form-control" placeholder="请输入参与人员" value="${businessTalk.joinMember}">
      </div>
    </div>

  </form>
  <!--===================================================-->
  <!-- END BASIC FORM ELEMENTS -->

  <div class="panel-footer">
    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
      <i class="fa fa-lg fa-mail-reply"></i> 返回
    </a>
    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
    <c:if test="${businessTalk==null || businessTalk.processState=='Draft'}">
      <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
    </c:if>
    <c:if test="${businessTalk!=null && businessTalk.processState=='Backed'}">
      <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
    </c:if>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";

  $(function(){
    var pdata= {
      keyId:$("#keyId").val(),
      entityName:"com.fz.us.oa.core.entity.com.BusinessTalk"
    };
    multiDuty(pdata);
    fn_businessTalk_input_validate()
  });

  $('#startDate,#endDate').datepicker({
    format: 'yyyy-mm-dd',
    weekStart: 1,
    autoclose: true,
    todayBtn: 'linked',
    todayHighlight: true,
    language: 'zh-CN'
  });

  inputLoad({
    objId:"talkFileName",
    entityName:"talkFileIds",
    sourceId:"talkFileId",
    jsessionid:"<%=jsessionid%>"
  });

  //选择客户信息
  function fn_customerInfo_dialog_select(){
    __open_dialog_select('客户信息', '<%=path%>/com/customerInfo/chooseCustomer', function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();
          $('#customerInfo').val(data.name);
          $('#customerInfoId').val(data.id);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_customerInfo_select(callback);
    });
  }

  // 表单数据校验
  function fn_businessTalk_input_validate() {
    __init_validate('form_businessTalk_input', {
      rules : {
        customerInfoId : {
          required : true
        },
        startDate : {
          required : true
        },
        endDate : {
          required : true
        },
        talkTopic : {
          required : true
        },
        talkType:{
          required : true
        },
        talkAddress:{
          required : true
        },
        talkObject:{
          required : true
        },
        talkContent:{
          required : true
        },
        talkFileIds:{
          required : true
        },
        joinMember:{
          required : true
        }
      },
      messages : {
        customerInfoId : {
          required : "请选择客户名称"
        },
        startDate : {
          required : "请选择开始时间"
        },
        endDate : {
          required : "请选择结束时间"
        },
        talkTopic : {
          required : "请输入洽谈主题"
        },
        talkType : {
          required : "请选择洽谈方式"
        },
        talkAddress : {
          required : "请输入洽谈地址"
        },
        talkObject : {
          required : "请输入洽谈对象"
        },
        talkContent : {
          required : "请输入洽谈内容"
        },
        talkFileIds : {
          required : "请上传内容附件"
        },
        joinMember : {
          required : "请输入参与人员"
        }
      }
    });
  }

  //保存
  $("#btn-save-common").click(function(){
    __confirm_dialog("提示","确定保存吗？",function(){
      __form_save("form_businessTalk_input", "<%=path%>/com/businessTalk/save",function(){
        $("#apply-re-common").trigger("click");
      })
    })
  });

  //提交
  $("#btn-commit-common,#btn-recommit-common").click(function(){
    if (!$('#form_businessTalk_input').valid()) {
      return false;
    }
    __confirm_dialog("提示","确定提交吗？",function(){
      __form_save("form_businessTalk_input", "<%=path%>/com/businessTalk/commit",function(){
        $("#apply-re-common").trigger("click");
      })
    })
  });


  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });

</script>